console.log(`代码运行`,);
const param = parseUrlParams(location.href)

setTimeout(() => {
    ReadyList()
}, 300)

console.log(`param`, param);
function AllReady() {
    switch (param.menucode) {
        // 分包商信息
        case "6028fc39-2fb4-2da2-db1c-5efb0ae37800":
            FbSupplyInfo()
            break;
        //供应商信息
        case "ce797034-22eb-07a9-19e5-25e1156aad84":
            break;
    }

}

function ReadyList() {
    if (param.otype) return
    switch (param.menucode) {
        // 分包商信息
        case "6028fc39-2fb4-2da2-db1c-5efb0ae37800":
            console.log(`分包商列表`,);
            const boxBtn = Ext.getCmp(document.querySelector("body").childNodes[0].id)
            const listGrid = Ext.getCmp("billList")
            const listBtn = Ext.getCmp(document.querySelector("body").childNodes[1].id)
            // 列表设置
            const queryBtn = Ext.getCmp(document.querySelector("body").childNodes[1].childNodes[0].id).queryById("query")
            const user_cs = listBtn.queryById("user_cs")
            user_cs.setValue("11,12")
            BatchBindCombox([listBtn.queryById("user_cs")])
            queryBtn.handler.call(queryBtn.scope)

            boxBtn.insert(8, {
                xtype: "button",
                text: "查看分包商业绩",
                iconCls: "icon-CheckView",
                handler: function () {
                    const row = listGrid.getSelectionModel().getSelection()[0];
                    console.log(`row`,row);
                    $OpenTab(`(${row.raw.CompName})新分包合同信息`,`http://10.52.119.173:30847/view/contract/?v=${Date.now()}#/CntMFor/list?AppTitle=%E5%90%88%E5%90%8C%E5%AE%A1%E6%89%B9&menucode=d628e85f-f0bf-7325-90b8-ac6c0e541f03&multiCooperate=0&busCode=PCM_INFO4&gys_phid=${row.raw.PhIdEnt}&gys_name=${row.raw.AccountName}`)
                 }
            })
            
            

            break;
        //供应商信息
        case "ce797034-22eb-07a9-19e5-25e1156aad84":
            break;
    }

}


// 分包商信息
function FbSupplyInfo() {
    const mstform = Ext.getCmp("entpriseform")
    const dgrid = Ext.getCmp("supplyfiletab")
    const dgrid2 = Ext.getCmp("SupplyfileItemGrid")
    // 设置供应商类型 镜像字段
    dgrid.queryById("SuppClassId").addListener("helpselected", function () {
        mstform.queryById("user_cs").setValue(String((Number(dgrid.queryById("SuppClassId").getValue()) || 0) || ""))
        BatchBindCombox([mstform.queryById("user_cs")])
    })
    dgrid2.getStore().on('datachanged', async function (dstore, eOpts) {
        const records = dstore.getRange();
        for(let record of records){
            record.set("PhIdRes","10003")
            record.set("PhIdRes_EXName","临时费用项")
        }
        dgrid2.refresh()
    })
}

function parseUrlParams(url) {
    let queryString = url.split('?')[1]; // 取出 ? 后面的部分
    if (!queryString) return {};

    return queryString.split('&').reduce((params, param) => {
        let [key, value] = param.split('=');
        params[decodeURIComponent(key)] = decodeURIComponent(value || '');
        return params;
    }, {});
}